import re

import aiohttp
import asyncio

# 命令捕获组（具名捕获组）
pattern = re.compile(r'<title>(?P<foo>.*?)</title>')

urls = [
    'https://www.python.org/',
    'https://www.taobao.com/',
    'https://pypi.org/',
    'https://www.git-scm.com/',
    'https://www.jd.com/',
    'https://opendata.sz.gov.cn/',
    'https://www.datacamp.com/'
]


async def show_title(url):
    """根据指定的URL获取网站标题"""
    async with aiohttp.ClientSession() as session:
        await asyncio.sleep(1)
        async with session.get(url, ssl=False) as resp:
            html_code = await resp.text()
            match = pattern.search(html_code)
            if match:
                print(match.group('foo'))


cos_list = [show_title(url) for url in urls]
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait(cos_list))
loop.close()
